<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/23 0023
 * Time: 17:26
 */

namespace app\admin\model;


use think\facade\Db;
use think\Model;

class Goods extends Model{
    protected $pk='goods_id';
//    public function getIfShowAttr($value){
//       if ($value==1){
//           return "<img src='/static/images/√.jpg'>";
//       }else{
//           return "<img src='/static/images/X.jpg'>";
//       }
//    }
//       public function getRecommendedAttr($value){
//           if ($value==1){
//               return "<img src='/static/images/√.jpg'>";
//           }else{
//               return "<img src='/static/images/X.jpg'>";
//           }
//
//    }
//    public function getIsShowAttr($value){
//        if ($value==1){
//            return "<img src='/static/images/√.jpg'>";
//        }else{
//            return "<img src='/static/images/X.jpg'>";
//        }
//
//    }
    public static function getGoodsList($where,$getorder){
        $list=Goods::
            alias('g')
            ->field('g.*,g.cate_name,g.add_time')
            ->field('c.cate_name')
            ->field('b.brand_name')
            ->order($getorder)
            ->where($where)
            ->join('ecm_gcategory c','c.cate_id=g.cate_id')
            ->join('ecm_brand b','g.brand=b.brand_id')
            ->paginate([
                'list_rows'=> 5,//每页数量
                'query' => request()->param(),
            ]);
        return $list;
    }

public static function addGoodsList($data){
        $good=new Goods();
        try{
         $res=$good->save($data);
         $msg='成功';
        }catch (\Exception $e){
         $res=false;
         $msg=$e->getMessage();
        }
        return[$res,$msg];
}

    public static function editGoodsList($data){
       try{
           $res=Goods::update($data);
           $msg='成功';
       }catch (\Exception $e){
           $res=false;
           $msg=$e->getMessage();
       }
       return[$res,$msg];
    }



public static function getGoods(){
    $list=Goods::
    alias('g')
        ->field('g.*,g.cate_name,g.add_time')
        ->field('c.cate_name')
        ->field('b.brand_name')
        ->join('ecm_gcategory c','c.cate_id=g.cate_id')
        ->join('ecm_brand b','g.brand=b.brand_id')
        ->paginate([
            'list_rows'=> 5,//每页数量
            'query' => request()->param(),
        ]);

    return $list;
}

}
